﻿using UnityEngine;
using UnityEditor;

public class PackerFileItem : ScriptableObject
{
    public string guid;
}

[CustomEditor(typeof(PackerFileItem))]
[CanEditMultipleObjects]
public class PackerFileItemInspector : Editor
{
    FilePackType GetTargetPack(Object t)
    {
        var guid = ((PackerFileItem)t).guid;
        return Packer.setting.GetFilePackType(guid);
    }

    FilePackType GetTargetsPack()
    {
        var pack = GetTargetPack(target);
        for (int i = 1; i < targets.Length; ++i)
        {
            var p = GetTargetPack(targets[i]);
            if (pack != p)
            {
                pack = (FilePackType)(-1);
                break;
            }
        }
        return pack;
    }

    void SetTargetsPack(FilePackType pack)
    {
        foreach (var t in targets)
        {
            Packer.setting.SetFilePackType(((PackerFileItem)t).guid, pack);
        }
        Packer.Refresh();
    }

    public override void OnInspectorGUI()
    {
        var pack = GetTargetsPack();
        var pack2 = (FilePackType)EditorGUILayout.EnumPopup("Type", pack);
        if (pack != pack2)
            SetTargetsPack(pack2);
    }
}
